using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;

namespace WeberTimeTracker.Models.Mapping
{
    public class AddressMap : EntityTypeConfiguration<Address>
    {
        public AddressMap()
        {
            // Primary Key
            this.HasKey(t => t.Address_ID);

            // Properties
            this.Property(t => t.Number)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.Street)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.Suite_apartment)
                .HasMaxLength(10);

            // Table & Column Mappings
            this.ToTable("Addresses");
            this.Property(t => t.Address_ID).HasColumnName("Address_ID");
            this.Property(t => t.Number).HasColumnName("Number");
            this.Property(t => t.Street).HasColumnName("Street");
            this.Property(t => t.Suite_apartment).HasColumnName("Suite_apartment");
            this.Property(t => t.City_ID).HasColumnName("City_ID");
            this.Property(t => t.State_ID).HasColumnName("State_ID");
            this.Property(t => t.Zip_ID).HasColumnName("Zip_ID");

            // Relationships
            this.HasRequired(t => t.City)
                .WithMany(t => t.Addresses)
                .HasForeignKey(d => d.City_ID);
            this.HasRequired(t => t.State)
                .WithMany(t => t.Addresses)
                .HasForeignKey(d => d.State_ID);
            this.HasRequired(t => t.Zip)
                .WithMany(t => t.Addresses)
                .HasForeignKey(d => d.Zip_ID);

        }
    }
}
